/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "stdafx.h"
#include <pgl/core/pgl.h>
#include <pgl/core/PGLRegionPropPage.h>
#include <pgl/core/PGLRegion.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPGLRegionPropPage property page

IMPLEMENT_DYNCREATE(CPGLRegionPropPage, CPropertyPage)

CPGLRegionPropPage::CPGLRegionPropPage(CPGLRegionStPtr pRegion) : CPropertyPage(CPGLRegionPropPage::IDD)
{
	//{{AFX_DATA_INIT(CPGLRegionPropPage)
	m_dNBBottom = 0.0;
	m_dNBLeft = 0.0;
	m_dNBRight = 0.0;
	m_dNBTop = 0.0;
	//}}AFX_DATA_INIT
	m_pRegion = pRegion;
}

CPGLRegionPropPage::~CPGLRegionPropPage()
{
}

void CPGLRegionPropPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPGLRegionPropPage)
	DDX_Text(pDX, IDC_PGL_EDIT_NB_BOTTOM, m_dNBBottom);
	DDV_MinMaxDouble(pDX, m_dNBBottom, 0., 1.);
	DDX_Text(pDX, IDC_PGL_EDIT_NB_LEFT, m_dNBLeft);
	DDV_MinMaxDouble(pDX, m_dNBLeft, 0., 1.);
	DDX_Text(pDX, IDC_PGL_EDIT_NB_RIGHT, m_dNBRight);
	DDV_MinMaxDouble(pDX, m_dNBRight, 0., 1.);
	DDX_Text(pDX, IDC_PGL_EDIT_NB_TOP, m_dNBTop);
	DDV_MinMaxDouble(pDX, m_dNBTop, 0., 1.);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPGLRegionPropPage, CPropertyPage)
	//{{AFX_MSG_MAP(CPGLRegionPropPage)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPGLRegionPropPage message handlers

BOOL CPGLRegionPropPage::OnSetActive() 
{
	PGL_ASSERT_VALID(m_pRegion);

	const CPGLRectD rNB=m_pRegion->GetOutsideBBox();

	m_dNBLeft=rNB.left;
	m_dNBBottom=rNB.bottom;
	m_dNBRight=rNB.right;
	m_dNBTop=rNB.top;
	
	UpdateData(FALSE);

	return CPropertyPage::OnSetActive();
}

BOOL CPGLRegionPropPage::OnKillActive() 
{
	UpdateData(TRUE);

	m_pRegion->SetNormBBox(static_cast<float>(m_dNBLeft), 
		static_cast<float>(m_dNBBottom), 
		static_cast<float>(m_dNBRight),
		static_cast<float>(m_dNBTop)
		);

	return CPropertyPage::OnKillActive();
}
